package com.myjavastring;

public class StringBuilderBuffer {
   static void  testString(){
      long start = System.currentTimeMillis();
       String str="";
       for (int i = 0; i < 10000; i++) {
           str+=i;
       }

      long end = System.currentTimeMillis();
       long res = end - start;
       System.out.println(res);

    }
    static void testBuilder(){
        long start = System.currentTimeMillis();
        StringBuilder str=new StringBuilder();
        for (int i = 0; i < 10000; i++) {
            str.append(i);
        }

        long end = System.currentTimeMillis();
        long res = end - start;
        System.out.println(res);

    }
    static void testBuffer(){
        long start = System.currentTimeMillis();
        StringBuffer str=new StringBuffer();
        for (int i = 0; i < 10000; i++) {
            str.append(i);
        }

        long end = System.currentTimeMillis();
        long res = end - start;
        System.out.println(res);
    }

    public static void main(String[] args) {
        testString();
        testBuilder();
        testBuffer();

    }
}

